package com.ruoyi.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.demo.domain.AuctionRule;
import com.ruoyi.demo.service.IAuctionRuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 竞拍规则Controller
 *
 * @author metaee
 * @date 2025-02-24
 */
@Api(tags = "竞拍规则管理")
@RestController
@RequestMapping("/demo/rule")
public class AuctionRuleController extends BaseController
{
    @Autowired
    private IAuctionRuleService auctionRuleService;

    /**
     * 查询竞拍规则列表
     */
    @ApiOperation("查询竞拍规则列表")
    @GetMapping("/list")
    public TableDataInfo list(AuctionRule auctionRule)
    {
        startPage();
        List<AuctionRule> list = auctionRuleService.selectAuctionRuleList(auctionRule);
        return getDataTable(list);
    }

    /**
     * 导出竞拍规则列表
     */
    @ApiOperation("导出竞拍规则列表")
    @Log(title = "竞拍规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuctionRule auctionRule)
    {
        List<AuctionRule> list = auctionRuleService.selectAuctionRuleList(auctionRule);
        ExcelUtil<AuctionRule> util = new ExcelUtil<AuctionRule>(AuctionRule.class);
        util.exportExcel(response, list, "竞拍规则数据");
    }

    /**
     * 获取竞拍规则详细信息
     */
    @ApiOperation("获取竞拍规则详细信息")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return success(auctionRuleService.selectAuctionRuleByRuleId(ruleId));
    }

    /**
     * 新增竞拍规则
     */
    @ApiOperation("新增竞拍规则")
    @Log(title = "竞拍规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuctionRule auctionRule)
    {
        return toAjax(auctionRuleService.insertAuctionRule(auctionRule));
    }

    /**
     * 修改竞拍规则
     */
    @ApiOperation("修改竞拍规则")
    @Log(title = "竞拍规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuctionRule auctionRule)
    {
        return toAjax(auctionRuleService.updateAuctionRule(auctionRule));
    }

    /**
     * 删除竞拍规则
     */
    @ApiOperation("删除竞拍规则")
    @Log(title = "竞拍规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(auctionRuleService.deleteAuctionRuleByRuleIds(ruleIds));
    }
}
